<?php

require_once APPLICATION_PATH.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'Component_Abstract.php';
class RandomImage extends Component_Abstract  {

	private $_file;
    
        public function setFile($data) {
            $this->_file=$data;
        }
        
        public function getFile() {
            return $this->_file;
        }

        public function initComponent() {
        
            
        }
        
	public function show() {

            $groupId = $this->getParameter('group_id');
            if (is_null($groupId))
                    throw new Exception("group_id is null");
            $imageGroup = new Default_Model_ImageGroups();
            $imageGroup->find($groupId);

            $image = new Default_Model_Images();
            $rows=$image->getImagesByGroupId($groupId);
            $randNum = rand(0,count($rows) - 1);
            $uri=$this->getImagesUri().'/'.$imageGroup->getPath().'/'.$rows[$randNum]['filename'];
            $this->setFile($uri);
            
            $ret=$this->getTmplContent($this->getConfig()->phtml->picturepage);
            return $ret;

	}

        public function demo() {
            $ret=$this->getTmplContent($this->getConfig()->phtml->demopage);
            return $ret;
        }

        public function getConfigPage() {

            return false;
            
        }

        public function getOptionsDiv() {

            $ret=$this->getTmplContent($this->getConfig()->phtml->optionspage);
            return $ret;

        }


}
